import dt from '@dt/dt'
import Opt from '@/components/dt/info/Opt.js'
import toolMgr from '@/biz/base/tool.js'

//标准 STANDARD
//预发 PRE
//保证金 DEPOSIT
//交房 HANDOVER
//特殊 SPECIAL
//年底 YEAR_END
//跳点 SKIP_POINT

class BillOpt extends Opt {

  constructor(info, name, type) {
    super(info)
    this.name = name
    this.type = type
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {

    let files = []
    if (this.info.accessoryBOList) {
      files = this.info.accessoryBOList.map(item => {
        return {
          value: item.accessoryName,
          key: item.accessoryUrl
        }
      })
    }

    this.all = [{
        title: '结算房源套数',
        key: 'roomNum',
        text: {},
      }, {
        title: '特殊奖金单类型',
        key: 'specialType',
        text: {
          type: 'dict',
          key: 'specialType'
        },
        visible: this.name != 'billEdit' && this.type == 'SPECIAL'
      }, {
        title: '原因',
        key: 'reason',
        text: {},
        visible: this.name != 'billEdit' && this.type == 'SPECIAL'
      },
      {
        title: '可结算房源总销',
        key: 'settlementSumAmount',
        labelWidth: 115,
        text: {
          type: 'number',
          unit: '元'
        },
        visible: this.type == 'STANDARD'
      },
      {
        title: '可结算代理费',
        key: 'sumAgentCost',
        labelWidth: 100,
        text: {
          type: 'number',
          unit: '元'
        },
        visible: this.type == 'STANDARD' || this.type == 'DEPOSIT' || this.type == 'SKIP_POINT'
      },
      {
        title: '应付奖金总额',
        key: 'bonusAmount',
        labelWidth: 100,
        text: {
          type: 'number',
          unit: '元'
        }
      }, {
        title: '本次发放类型',
        labelWidth: 160,
        text: {},
        data: {
          from: (info) => {
            if (!info.specialGrantType) {
              return `${info.settlementRatio}%-${info.yearEndRatio}%-${info.handoverRatio}%`
            } else if (info.specialGrantType == 'PRE' || info.specialGrantType == 'BACK_COMM') {
              let str = dt.dictInfo().__value('specialGrantType', info.specialGrantType)
              str = info.preRatio != null ? `${str}(${info.preRatio}%) ` : `${str} `
              return `${str}${info.settlementRatio}%-${info.yearEndRatio}%-${info.handoverRatio}%`
            } else {
              return dt.dictInfo().__value('specialGrantType', info.specialGrantType)
            }
          }
        },
        visible: this.name != 'billEdit' && this.type == 'SPECIAL'
      }, {
        title: 'oa文电编号',
        key: 'oaCode',
        labelWidth: 160,
        text: {},
        visible: this.name != 'billEdit' && this.type == 'SPECIAL'
      }, {
        title: '附件',
        key: 'accessoryBOList',
        col: 24,
        visible: this.name != 'billEdit',
        tag: {
          type: 'text',
          closable: false,
          options: files,
          color: 'blue',
          click: (tag) => {
            toolMgr.downloadFile(tag.key, tag.value)
          }
        }
      }, {
        title: '备注',
        col: 24,
        key: 'remark',
        visible: this.name != 'billEdit',
        text: {}
      }
    ]
  }
}

export default BillOpt
